home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / drivers / mscdex / testdrv / setup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-23  |  11.0 KB  |  427 lines

  1. /* TESTDRV
  2. ** 
  3. ** FILE:    setup.c
  4. **      
  5. ** Set up and profile parser
  6. **
  7. ** The methods here are simple.  Global values are initialized
  8. ** to defaults and modified according to the profile information.
  9. ** The profile parsing is line-by-line with a simple <word><delimiter>
  10. ** format.
  11. **
  12. ** HISTORY:
  13. **      10/01/90 Final (v1.0) -by- JYG
  14. **    12/06/91 Revision  - Siddhartha Roy 
  15. */
  16.  
  17. #include<stdlib.h>
  18. #include<string.h>
  19.  
  20. #include"test.h"
  21.  
  22. #define MAXLABEL        40
  23. #define MAXSTRING       256
  24.  
  25.  
  26. static WORD cLineNo=0;
  27.  
  28. /*
  29. ** syntaxError() -
  30. */
  31.  
  32. static void syntaxError(msg)
  33. char * msg;
  34. {
  35.     printf("%s: Syntax Error Parsing Profile : line %d : %s\n",PROGNAME,cLineNo,msg);
  36.     exit(1);
  37. }
  38.  
  39. /* lookup() -
  40. **
  41. ** Sequential strcmpi full word lookup of all settable flags
  42. ** uses (static char *) szLabelTable[];
  43. ** returns the integer lookup index or -1 if not found
  44. */
  45.  
  46. static short lookup ( szLabel )
  47. char    *szLabel;
  48. {
  49.     short i;
  50.     for(i=0;i<NUM_VALS;i++)     // lookup
  51.            if (strlen(szLabelTable[i]) == strlen(szLabel) &&
  52.                strcmpi(szLabelTable[i],szLabel) == 0)
  53.                return i;
  54.     return ( -1 );
  55. }
  56.  
  57. /* getNextLine() -
  58. **
  59. ** Cook out the first useful string on a new line.
  60. ** Returns a pointer to the first useful character on the string
  61. */
  62.  
  63. static char *getNextLine( pchBuf,pInFile )
  64. char    *pchBuf;
  65. FILE    *pInFile;
  66. {
  67.     short i=0;
  68.  
  69.     do
  70.     {
  71.         cLineNo++;
  72.         if (fgets(pchBuf,MAXSTRING,pInFile) == NULL)
  73.             return ( NULL );
  74.         for (i=0;isspace(pchBuf[i]);i++); // advance pointer to next char
  75.  
  76.     }
  77.  
  78.     //Skip these chars too and fetch a new line 
  79.  
  80.     while (pchBuf[i] == ';' || pchBuf[i] == '\0');
  81.  
  82.     return ( pchBuf+i );
  83. }
  84.  
  85. /*
  86. **  copies the next alpha string into the pchDest from pchSrc and
  87. **  returns a pointer to the next alpha string.
  88. **  pchDelim gets the value of the delimeter that ends the
  89. **  alpha string
  90. */
  91.  
  92. static char *getNextString(pchDest,pchSrc,pchDelim)
  93. char    *pchDest;
  94. char    *pchSrc;
  95. char    *pchDelim;
  96. {
  97.     for(;isspace(*pchSrc);pchSrc++);    // eliminate whitespace
  98.     for(;isgraph(*pchSrc) && *pchSrc != ',' && *pchSrc != '=';
  99.         *pchDest++=*pchSrc++);          // copyto
  100.     *pchDest = '\0';
  101.     for(;isspace(*pchSrc);pchSrc++);    // eliminate whitespace
  102.     if (*pchSrc=='\0'|| *pchSrc == ';'){// end of line reached
  103.         *pchDelim = '\n';
  104.         return NULL;
  105.     }
  106.     *pchDelim=*pchSrc;          // return delimeter
  107.     return ( pchSrc+1 );            // return advanced ptr
  108. }
  109.  
  110. /* getBool() -
  111. **
  112. **  Anticipated Boolean ([t|true] | [f|false]) is
  113. **  extracted and the value returned.
  114. **  Syntax error if none is found
  115. */
  116.  
  117. static char getBool(pchSrc)
  118. char * pchSrc;
  119. {
  120.  
  121.     char * pchNext, pchDest[MAXSTRING],pchDelim;
  122.  
  123.     pchNext = getNextString(pchDest,pchSrc,&pchDelim);
  124.  
  125.     if (strlen(pchDest) == 1) {
  126.         if (tolower(pchDest[0]) == 't')
  127.             return TRUE;
  128.         else if (tolower(pchDest[0]) == 'f')
  129.             return FALSE;
  130.         else syntaxError("Parsing BOOLEAN");
  131.     } else if (strcmpi(pchDest,"true")==0)
  132.         return TRUE;
  133.     else if (strcmpi(pchDest,"false")==0)
  134.         return FALSE;
  135.     else    syntaxError("Parsing BOOLEAN");
  136.  
  137. }
  138.  
  139. /*
  140. ** Due to the nature of the test, more levels of verbosity can
  141. ** be incorporated (terse,normal,verbose).  Currently there are
  142. ** only terse and verbose modes.
  143. */
  144.  
  145. /* setup()
  146. **
  147. ** Parses the input file and sets appropriate flags.
  148. */
  149.  
  150. void    setup(pInFile)
  151. FILE    * pInFile;
  152. {
  153.  
  154.     extern FILE * pOutFile;
  155.     extern FLAG fWriteMedia, fRedbook, fRaw, fPrefetch, fAudCtrl, fAudio,
  156.         fInterleave, fEject, fUPC, fVerbose, fPrep, fSubInfo;
  157.     extern BYTE bInterSize,bInterSkip;
  158.     extern char szDriverName[8], *szProfileName;
  159.     extern WORD cwAudioChan,cwHSGSectors,cwRedSectors;
  160.     extern WORD cwErrors, cwWarnings, cwRequests;
  161.     extern DWORD mplHSGSector[],mplRedSector[];
  162.     extern char *szStdPath;
  163.  
  164. #ifdef DEBUG
  165.     static char szTrue[] = "TRUE";
  166.     static char szFalse[] = "FALSE";
  167. #endif
  168.     
  169.     char    szSrc[MAXSTRING],szDest[MAXSTRING],*pchNext,chDelim;
  170.     DWORD   dwMin,dwSec,dwFrame;
  171.  
  172.     //  Presetting Defaults
  173.     // If a flag is left UNSET, the fields of DevStat will be
  174.     // used to set the values
  175.  
  176.     pOutFile    = stdout;
  177.     fWriteMedia = UNSET;
  178.     fRedbook    = UNSET;
  179.     fRaw        = UNSET;
  180.     fPrefetch   = UNSET;
  181.     fAudCtrl    = UNSET;
  182.     fAudio      = UNSET;
  183.     fInterleave = UNSET;
  184.     fEject      = UNSET;
  185.     fUPC        = UNSET;
  186.     fSubInfo    = UNSET;
  187.     
  188.     cwAudioChan = 2;
  189.     cwRedSectors= 0;
  190.     cwHSGSectors= 0;
  191.     bInterSize  = 0;
  192.     bInterSkip  = 0;
  193.     cwWarnings  = 0;
  194.     cwRequests  = 0;
  195.     cwErrors    = 0;
  196.     
  197.     while ((pchNext = getNextLine(szSrc,pInFile)) != NULL) {
  198.  
  199.     // Point to next useful character
  200.  
  201.         pchNext = getNextString(szDest,szSrc,&chDelim);
  202.     if (pchNext == NULL || chDelim != '=')
  203.             syntaxError(szIllChar);
  204.     // Switch on index 
  205.         switch ( lookup(szDest) ) {
  206.             case laDRIVERNAME:
  207.                 if (getNextString(szDriverName,pchNext,&chDelim)!=NULL)
  208.                     syntaxError(szSpurCh);
  209.                 {
  210.                     BYTE cLen = (BYTE)strlen(szDriverName);
  211.             // Pad up the rest
  212.                     for (;cLen<8;cLen++)
  213.                         szDriverName[cLen] = ' ';
  214.                 }
  215.                 
  216.  
  217. #ifdef DEBUG
  218. printf("Driver: '%s'\n", szDriverName);
  219. #endif
  220.  
  221.                 break;
  222.  
  223.             case laWRITEDEVICE:
  224.         ChkRepeat(fWriteMedia);
  225.                 fWriteMedia = getBool(pchNext);
  226.  
  227. #ifdef DEBUG
  228. printf("Write: %s\n",fWriteMedia?szTrue:szFalse);
  229. #endif
  230.                 break;
  231.             case laREDBOOK:
  232.         ChkRepeat(fRedbook);
  233.                 fRedbook = getBool(pchNext);
  234. #ifdef DEBUG
  235. printf("Redbook: %s\n",fRedbook?szTrue:szFalse);
  236. #endif
  237.                 break;
  238.             case laRAWMODE:
  239.         ChkRepeat(fRaw);
  240.                 fRaw = getBool(pchNext);
  241. #ifdef DEBUG
  242. printf("Raw: %s\n",fRaw?szTrue:szFalse);
  243. #endif
  244.                 break;
  245.             case laPREFETCH:
  246.         ChkRepeat(fPrefetch);
  247.                 fPrefetch = getBool(pchNext);
  248. #ifdef DEBUG
  249. printf("Prefetch: %s\n",fPrefetch?szTrue:szFalse);
  250. #endif
  251.                 break;
  252.             case laAUDIOCNTRL:
  253.         ChkRepeat(fAudCtrl);
  254.                 fAudCtrl = getBool(pchNext);
  255. #ifdef DEBUG
  256. printf("AudioCtrl: %s\n",fAudCtrl?szTrue:szFalse);
  257. #endif
  258.                 break;
  259.             case laAUDIOCAPABLE:
  260.         ChkRepeat(fAudio);
  261.                 fAudio = getBool(pchNext);
  262. #ifdef DEBUG
  263. printf("Audio: %s\n",fAudio?szTrue:szFalse);
  264. #endif
  265.                 break;
  266.             case laAUDIOCHANNELS:
  267.                 if (getNextString(szDest,pchNext,&chDelim) !=
  268.                     NULL)
  269.                     syntaxError(szSpurCh);
  270.                 cwAudioChan = (short)atoi(szDest);
  271. #ifdef DEBUG
  272. printf("%d Audio channels\n", cwAudioChan);
  273. #endif
  274.                 break;
  275.             case laINTERLEAVE:
  276.         ChkRepeat(fInterleave);
  277.                 fInterleave = getBool(pchNext);
  278. #ifdef DEBUG
  279. printf("Interleave: %s\n ",fInterleave?szTrue:szFalse);
  280. #endif
  281.  
  282.                 break;
  283.             case laEJECT:
  284.         ChkRepeat(fEject);
  285.                 fEject = getBool(pchNext);
  286. #ifdef DEBUG
  287. printf("Eject: %s\n",fEject?szTrue:szFalse);
  288. #endif
  289.                 break;
  290.             case laUPCCODE:
  291.         ChkRepeat(fUPC);
  292.                 fUPC = getBool(pchNext);
  293. #ifdef DEBUG
  294. printf("UPC: %s\n",fUPC?szTrue:szFalse);
  295. #endif
  296.                 break;
  297.             case laOUTPUT:
  298.                 if (getNextString(szDest,pchNext,&chDelim)
  299.                     !=NULL)
  300.                     syntaxError(szSpurCh);
  301.  
  302. #ifdef DEBUG
  303. printf("OUTFILE: %s\n",szDest);
  304. #endif
  305.                 if (fPrep) {
  306.                     if ((pOutFile = fopen(szDest,"w+b"))==NULL)
  307.                         syntaxError("Couldn't open binary file");
  308.                 }
  309.                 else if ((pOutFile = fopen(szDest,"w"))==NULL)
  310.                     syntaxError("Couldn't open output file");
  311.  
  312.                 break;
  313.  
  314.             case laREDSECTORS:
  315.                 do {
  316.                     pchNext = getNextString(szDest,
  317.                         pchNext,&chDelim);
  318.                     sscanf(szDest,"%U:%U:%U",&dwMin,&dwSec,
  319.                         &dwFrame);
  320.                     mplRedSector[cwRedSectors++] =
  321.                         ((0x0000ffff&dwMin)<<16)|((0x0000ffff&dwSec)<<8)|
  322.                             (0x0000ffff&dwFrame);
  323.  
  324. #ifdef DEBUG
  325.                     PrintRed(mplRedSector[cwRedSectors-1]);
  326.                     putchar('\n');
  327. #endif
  328.                 } while ( pchNext != NULL );
  329. #ifdef DEBUG
  330. printf("%d Red Sectors\n",cwRedSectors);
  331. #endif
  332.                 break;
  333.  
  334.             case laHSGSECTORS:
  335.  
  336.                 do {
  337.                     pchNext = getNextString(szDest,
  338.                         pchNext,&chDelim);
  339.  
  340.  
  341.                     sscanf(szDest,"%lx",mplHSGSector
  342.                         +cwHSGSectors);
  343. #ifdef DEBUG
  344. printf(" HSG Sector %lx\n",mplHSGSector[cwHSGSectors]);
  345. #endif
  346.                 cwHSGSectors++;
  347.  
  348.                 } while ( pchNext != NULL );
  349.                 break;
  350.             case laINTERSKIP:
  351.                 if (getNextString(szDest,pchNext,&chDelim) !=NULL)
  352.                     syntaxError(szSpurCh);
  353.                 bInterSkip = (BYTE)atoi(szDest);
  354. #ifdef DEBUG
  355. printf("%d InterleaveSkip\n", bInterSkip);
  356. #endif
  357.                 break;
  358.  
  359.             case laINTERSIZE:
  360.                 if (getNextString(szDest,pchNext,&chDelim) !=NULL)
  361.                     syntaxError(szSpurCh);
  362.                 bInterSize = (BYTE)atoi(szDest);
  363. #ifdef DEBUG
  364. printf("%d InterleaveSize\n", bInterSize);
  365. #endif
  366.                 break;
  367.             case laSUBINFO:
  368.         ChkRepeat(fSubInfo);
  369.                 fSubInfo = getBool(pchNext);
  370. #ifdef DEBUG
  371. printf("Subinfo: %s\n",fSubInfo?szTrue:szFalse);
  372. #endif
  373.                 break;
  374.  
  375.             default:
  376.                 syntaxError(szUnreck);
  377.         }
  378.     }
  379.  
  380.     // Set up defaults
  381.  
  382.     if (szDriverName == NULL)
  383.         syntaxError(szNodrname);
  384.  
  385.     if (fWriteMedia == UNSET)
  386.         fWriteMedia = FALSE;
  387.     if (fRedbook == UNSET)
  388.         fRedbook = TRUE;
  389.     if (fRaw == UNSET)
  390.         fRaw = TRUE;
  391.     if (fPrefetch == UNSET)
  392.         fPrefetch = FALSE;
  393.     if (fAudCtrl == UNSET)
  394.         fAudCtrl = TRUE;
  395.     if (fAudio == UNSET)
  396.         fAudio = TRUE;
  397.     if (fSubInfo == UNSET)
  398.         fSubInfo = FALSE;
  399.     
  400.     if (fInterleave == UNSET)
  401.     {
  402.         fInterleave = FALSE;
  403.         if (bInterSkip != 0 || bInterSize !=0)
  404.             syntaxError(szBadintlv);
  405.     }
  406.  
  407.  
  408.     if (fEject == UNSET)
  409.         fEject = TRUE;
  410.     if (fUPC == UNSET)
  411.         fUPC = TRUE;
  412.     if (fVerbose == UNSET)
  413.         fVerbose = FALSE;
  414.     fclose(pInFile);
  415.  
  416. }
  417.  
  418. // Routine to check if a keyword is repeated in profile
  419. // New routine added
  420.  
  421. static void ChkRepeat(cdflag)
  422. FLAG cdflag;
  423. {
  424.       if (cdflag != UNSET)
  425.             syntaxError(szRepKey);
  426. }
  427.